<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Sugar</title>
</head>

<body>
  <script>

    const obj = {
      name: '肉丝rose',
      age: 18,
      gender: '女',
      // 丈夫
      husband: {
        name: '鱼香',
        age: 25,
        gender: '大汉'
      }
    }
    // console.log(obj.husband.name);

    // 1️⃣解构对象的一级属性
    // const { name, age, gender, husband } = obj
    // console.log('name', name);
    // console.log('age', age);
    // console.log('gender', gender);
    // console.log('husband', husband);


    // 2️⃣解构对象的二级属性 - 注意：一定要确保一级解构对象成功，否则会报错
    const { husband: { name, age, gender } } = obj
    console.log('name', name);
    console.log('age', age);
    console.log('gender', gender);

  </script>
</body>

</html>